/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package validator;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Valentina
 */
public class FormValidator {

    private static final String PASSWORD_PATTERN = "^[a-zA-Z0-9_-]{6,20}";
    private static Pattern pattern = Pattern.compile(PASSWORD_PATTERN);
    private static Matcher matcher;
    
    public static List myErrors = new ArrayList();

    public static List verifyRequiredField(String field, String fieldName) {
        if (field != null && field.length() == 0) {
            myErrors.add("Field " + fieldName + " is required!");
        }
        return myErrors;
    }

    public static List verifyPasswordField(String password) {
        matcher = pattern.matcher(password);
        
        if (!matcher.matches()) {
            myErrors.add("Password is to small");
        }

        return myErrors;
    }
}